
pkg load signal

[x, fs] = audioread('20-24k-sweep.wav');

fs = 48000;
fcuts = [8000*0.96 8000];
mags = [1 0];
devs = [0.01 0.001];


%  The Kaiser window parameters n and beta are computed from the
%  relation between ripple (A=-20*log10(dev)) and transition width (dw
%  in radians) discovered empirically by Kaiser:

%                 / 0.1102(A-8.7)                        A > 50
%          beta = | 0.5842(A-21)^0.4 + 0.07886(A-21)     21 <= A <= 50
%                 \ 0.0                                  A < 21

%          n = (A-8)/(2.285 dw)

%  Example:
%       [n, w, beta, ftype] = kaiserord ([1000, 1200], [1, 0], [0.05, 0.05], 11025);
%       b = fir1 (n, w, kaiser (n+1, beta), ftype, "noscale");
%       freqz (b, 1, [], 11025);


[n,Wn,beta,ftype] = kaiserord(fcuts, mags, devs, fs)
hh = fir1(n, Wn, ftype, kaiser(n+1, beta), 'noscale');

freqz(hh)

%y = filter(hh, 1, x);
%y = y(1:3:end);

%plot(y)
%audiowrite('out.wav', y, fs / 3);




